package leetcode.treeCode.week4.leetcode_530;

class Solution {
    private TreeNode prev;
    private int minDiff = Integer.MAX_VALUE;
    public int getMinimumDifference(TreeNode root) {
        dfs(root);
        return minDiff;
    }
    private void dfs(TreeNode node){
        if (node == null) return;
        dfs(node.left);
        // 中序遍历位置
        if (prev != null){
            minDiff = Math.min(minDiff, node.val - prev.val);
        }
        prev = node;
        dfs(node.right);
    }
}